import 'dart:ui';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_reader/model/novel.dart';
import 'package:flutter_reader/res/colors.dart';
import 'package:flutter_reader/ui/bookshelf/novel_cover_image.dart';
import 'package:flutter_reader/utils/screen.dart';

class NovelDetailHeader extends StatelessWidget {
  final Novel novel;
  NovelDetailHeader(this.novel);

  @override
  Widget build(BuildContext context) {
    var width = Screen.width;
    var height = 218.0 + Screen.topSafeHeight;
    return Container(
      width: width,
      height: height,
      child: Stack(
        children: [
          Image(
            image: CachedNetworkImageProvider(novel.imgUrl),
            fit: BoxFit.fitWidth,
            width: width,
            height: height,
          ),
          Container(color: Color(0xbb000000), width: width, height: height),
          BackdropFilter(
            filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
            child: _buildContent(),
          ),
        ],
      ),
    );
  }

  Widget _buildContent() {
    var width = Screen.width;
    return Container(
      width: width,
      padding: EdgeInsets.fromLTRB(15, 54 + Screen.topSafeHeight, 10, 0),
      color: Colors.transparent,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          NovelCoverImage(novel.imgUrl, width: 100, height: 133),
          SizedBox(width: 15),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  novel.name,
                  maxLines: 2,
                  style: TextStyle(
                      fontSize: 18,
                      color: Colors.white,
                      fontWeight: FontWeight.bold),
                ),
                SizedBox(height: 15),
                Text(
                  novel.author,
                  style: TextStyle(fontSize: 14, color: MyColors.white),
                ),
                SizedBox(height: 15),
                Text(
                  '${novel.firstCateName ?? ''} ${novel.wordCount}万字',
                  style: TextStyle(fontSize: 14, color: MyColors.white),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
